
path = strcat(datapath,'train_item.dat');
base = load(path);
alldata = base(:,1:3);
alldata(:,1) = alldata(:,1)+1;
alldata(:,2) = alldata(:,2)+1;
clear base
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%
%          important :                %
% userId and ItemId is from 0, not 1  %
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%
num_rates = size(alldata,1);

if mod(num_users, batchsize)==0
    numbatches = num_users/batchsize;
else
    numbatches = floor(num_users/batchsize)+1;
end
%numbatches = round(num_users/batchsize)

rate_matrix_d = zeros(num_users+batchsize, num_items*5);
rate_matrix = boolean(rate_matrix_d);
clear rate_matrix_d

rate_matrix_double = zeros(num_users+batchsize, num_items*5);


fprintf(1, 'i am here1111~');


tmp_index = 0;
for m=1:num_rates
    if mod(m,10000)==0
        fprintf(1,'%4.9f\n',m/num_rates);
    end
    tmp_index = alldata(m,2)*5-5;
    rate_matrix(alldata(m,1), tmp_index+alldata(m,3)) = 1;
    rate_matrix_double(alldata(m,1), tmp_index+1:tmp_index+5) = 1;
end

rate_matrix_real = boolean(rate_matrix_double);
clear rate_matrix_double
fprintf(1, 'i am here2222~');

batchdata_d = zeros(batchsize, num_items*5, numbatches);
batchdata = boolean(batchdata_d);
clear batchdata_d

batchdata_double = zeros(batchsize, num_items*5, numbatches);
batchdata_real = boolean(batchdata_double);
clear batchdata_double

for b=1:numbatches
    batchdata(:,:,b) = rate_matrix((b-1)*batchsize+1:batchsize*b, :);
    batchdata_real(:,:,b) = rate_matrix_real((b-1)*batchsize+1:batchsize*b, :);
end



fprintf(1, 'i am here3333~');



%����Ԥ�����MAE
testpath =strcat(datapath, 'test_item.dat');
test = load(testpath);
test_real = test(:,1:3);
test_real(:,1) = test_real(:,1)+1;
test_real(:,2) = test_real(:,2)+1;

clear test
test_size = size(test_real,1);

test_real_matrix = zeros(num_users, num_items);
for m=1:size(test_real,1)
    test_real_matrix(test_real(m,1),test_real(m,2)) = test_real(m,3);
end
test_template = test_real_matrix>0;




